define(function () {
    'use strict';

    function ctrl($scope, $filter,$stateParams,InfoService,$ionicLoading,CommonService) {

        $scope.channel = {};

        $scope.$on('$ionicView.beforeEnter', function() {
            init();
        });

        $scope.doRefresh = function() {
            init().finally(function(){
                $scope.$broadcast('scroll.refreshComplete');
            });
        };

        function init(){
            $scope.channel.channelId = $stateParams['id'];
            if(!$scope.items){
                $ionicLoading.show();
            }

            return queryContentBriefs();
        }

        function queryContentBriefs(){
            return InfoService.getProductsByChannelId($scope.channel.channelId).then(function(data){
                if(data){
                    $scope.items = data;
                    for(var i=0;i<data.length;i++){
                        var fund = $scope.items[i];
                        fund.prod_min_subscribe = $filter('prodMinSubscribe')(CommonService.getMinAmount(fund));
                    }
                }
                $ionicLoading.hide();
            });
        }
    }

    ctrl.$inject = ['$scope','$filter','$stateParams','InfoService','$ionicLoading','CommonService'];
    return ctrl;
});